home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Libraries / Graphic Elements 2 / LibHeaders / Defs.h next >
Encoding:
C/C++ Source or Header  |  1994-06-26  |  7.5 KB  |  251 lines  |  [TEXT/MPS ]

  1. /*
  2.     Defs.h
  3.     
  4.     Type definitions for Graphic Elements release version 1.5b1
  5.     
  6.     Copyright 1994 by Al Evans. All rights reserved.
  7.     
  8.     6/26/94
  9.     
  10.     
  11. */
  12.  
  13. #ifndef GEDEFS
  14. #define GEDEFS
  15. //Get Toolbox symbols if we're compiling in MPW
  16. #ifdef applec
  17. #ifndef __cplusplus
  18. #ifndef PRELOAD
  19. #pragma load "::ToolKit.precompile"
  20. #define PRELOAD
  21. #endif
  22. #endif
  23. #endif
  24.  
  25. #ifndef __QDOFFSCREEN__
  26. #include <QDOffscreen.h>
  27. #endif
  28.  
  29. #ifndef __TIMER__
  30. #include <Timer.h>
  31. #endif
  32.  
  33. //Are we using the new headers?
  34. #if defined(__CONDITIONALMACROS__)
  35. #define NEWHEADERS 1
  36. #else
  37. #define NEWHEADERS 0
  38. #endif
  39.  
  40. //Is this for the PowerMac?
  41. #if (defined(powerc) || defined(__powerc))
  42. #define FORPPC 1
  43. #else
  44. #define FORPPC 0
  45. #endif
  46.  
  47. #include "List.h"
  48.  
  49. //All offscreen graphics are presently 8 bits deep
  50. #define    offscrnDepth    8
  51.  
  52. //Some forward declarations
  53. typedef struct GrafElement *GrafElPtr;
  54. typedef struct GEWorld *GEWorldPtr;
  55.  
  56. //Built-in directions
  57. typedef enum {none, up, left, down, right, upLeft, upRight, downLeft, downRight} GEDirection;
  58.  
  59. //Constant for "same-size" worlds
  60. #define scaleOneToOne 0x00010000
  61.  
  62. /* 
  63.     Prototype of function to initialize a graphic element from a resource or series
  64.     of resources. This function is responsible for creating an offscreen GWorld
  65.     for the element if required, and rendering the resource(s) into it.
  66.     
  67.     This function is responsible for setting the fields element->resID, element->graphRect,
  68.     and element->graphWorld.
  69. */
  70.  
  71. typedef pascal Boolean (*GraphicLoadFunc) (GEWorldPtr world, GrafElPtr element,
  72.                             short startResNum, short nResources);
  73.  
  74. /*
  75.     Prototype for general-purpose bit copy function type-compatible with CopyBits.
  76.     BitCopyProcs are normally used for offscreen-to-offscreen copying only.
  77.     NOTE THAT THE PARAMETER maskRgn IS ALMOST NEVER A MASK REGION!  It is passed
  78.     from the drawData field of the graphic record. It should normally be nil, but
  79.     can be used for data required by a specific custom bitcopying procedure.
  80.     
  81.     If the "real" CopyBits is used directly for offscreen-to-offscreen drawing, care must be
  82.     taken that this field is nil or contains a real region handle.
  83. */
  84.  
  85. typedef pascal void (*BitCopyProc) (const BitMap *srcBits,const BitMap *dstBits,const Rect *srcRect,
  86.     const Rect *dstRect, short mode, RgnHandle maskRgn);
  87.     
  88. /*
  89.     Prototype for autochange procedure, which periodically moves graphic,
  90.     changes frames, scrolls graphic, etc.
  91. */
  92.  
  93. typedef pascal void (*AutoChangeProc) (GEWorldPtr world, GrafElPtr element);
  94.  
  95. /*
  96.     Prototype for interact procedure, which handles collisions
  97. */
  98.  
  99. typedef enum {collisionBegin, collisionContinue, collisionEnd} CollisionPhase;
  100.  
  101. typedef pascal void (*CollisionProc)(GEWorldPtr world, GrafElPtr element, 
  102.                             GEDirection dir, CollisionPhase phase, GrafElPtr hitElement);
  103.     
  104. /*
  105.     Prototype for rendering procedure to draw element into offscreen "stage" world
  106. */
  107.  
  108. typedef pascal void (*RenderProc)(GrafElPtr element, GWorldPtr destGWorld);
  109.  
  110. /*
  111.     Prototype for sensor-tracking procedure, called when mouse button is pressed
  112.     in a graphic element with sensor properties
  113. */
  114.  
  115. typedef pascal Boolean (*SensorTrack)(GEWorldPtr world, GrafElPtr sensor);
  116.  
  117. /*
  118.     Prototype for action procedure to be called by sensor
  119. */
  120.  
  121. typedef pascal void (*SensorAction)(GEWorldPtr world, short sensorState);
  122.  
  123. /*
  124.     Prototype for "custom" dispose procedure, called when Graphic Element is 
  125.     disposed to give element a chance to free up any memory it has allocated.
  126. */
  127.  
  128. typedef pascal void (*CleanupProc)(GEWorldPtr world, GrafElPtr element);
  129.  
  130. /*
  131.     Defined values for flags field of Graphic Element. Bits 5-13 are reserved
  132.     for future system use, bits 16-31 are available for use in defining
  133.     custom Graphic Elements.
  134. */
  135.  
  136. enum {    geShown =        0x00000001L,
  137.         geChanged =        0x00000002L,
  138.         geHit =            0x00000004L,
  139.         geSensor =        0x00000008L,
  140.         geForward =        0x00000010L,
  141.         geMirrored =    0x00004000L,
  142.         geInverted =    0x00008000L
  143.     };
  144.     
  145. /*
  146.     The structure of an entry in a world's sensorList
  147. */
  148.  
  149. typedef struct SensorListEntry *SListEntryPtr;
  150.  
  151. typedef struct SensorListEntry {
  152.     SListEntryPtr    nextEntry;
  153.     Rect            sensorRect;
  154.     OSType            sensorID;
  155. } SensorListEntry;
  156.  
  157. /*
  158.     The variable-rate timer for a GEWorld
  159. */
  160.  
  161. //Timer "rate" for 1 ms world time/ms real time
  162. #define geTimerStdRate 0x00010000
  163.  
  164. typedef struct {
  165.     TMTask            aTMTask;
  166.     unsigned long    currentTime;
  167.     long             currentRate;
  168.     long            timeAccum;
  169.     Boolean            running;
  170. } GETMgrRec, *GETMgrRecPtr;
  171.  
  172.  
  173.     
  174. /*
  175.     A basic Graphic Element
  176. */
  177.  
  178. typedef struct GrafElement{
  179.  
  180.     //Bookkeeping and access
  181.     GrafElPtr        nextByPlane;        //Link in world's drawList
  182.     GrafElPtr        nextByID;            //Link in world's idList
  183.     GrafElPtr        masterGrafEl;        //Master (if any) controls movement of this GrafEl
  184.     GrafElPtr        slaveGrafEl;        //This GrafEl controls movement of slave (if any) 
  185.     OSType            objectID;            //This element's "name"
  186.     short            drawPlane;            //"Level" of object, higher number == closer to front
  187.     short            resID;                //# of resource from which element was derived, if any
  188.     long            flags;                //See definitions above
  189.     CleanupProc        cleanupProc;        //Custom dispose procedure, if any
  190.     
  191.     //Basic graphics data
  192.     GWorldPtr        graphWorld;            //Ptr to offscreen graphic, if any
  193.     Rect            graphRect;            //Source rectangle used by RenderProc
  194.     Rect            animationRect;        //Total dest rectangle, GEWorld coordinates
  195.     RenderProc        renderIt;            //Element's rendering procedure
  196.     BitCopyProc        drawIt;                //Lowlevel bit copier, if any
  197.     Ptr                drawData;            //Data passed to drawIt, if any
  198.     Rect            drawRect;            //Rect to update on this cycle
  199.     short            copyMode;            //Bit transfer mode
  200.  
  201.     //For automatic periodic changes
  202.     short            changeIntrvl;        //Interval between automatic changes
  203.     unsigned long    lastChangeTime;        //Last time autochange proc was called
  204.     AutoChangeProc    changeIt;            //Function for automatic changes
  205.     Ptr                changeData;            //Extra data for automatic changes
  206.     
  207.     //For collisions
  208.     CollisionProc    doCollision;        //Proc called when element collides
  209.     short            collisionPlane;        //Collides only with elements on this plane
  210.     GrafElPtr        collideElement;        //Other element involved in this collision
  211.     
  212.     //For direct user interactions
  213.     short            sensorType;            //Used to distinguish variant types
  214.     SensorTrack        trackingProc;        //Called when mousedown in sensor's rectangle
  215.     SensorAction    actionProc;            //Called by trackingProc when sensor is "activated"
  216.     short            sensorState;        //For whatever a sensor needs to save across calls
  217. } GrafElement;
  218.     
  219. /*
  220.     A world of Graphic Elements
  221. */
  222.  
  223. typedef struct GEWorld {
  224.  
  225.     //Objects maintained by this world
  226.     GrafElPtr            drawList;        //Head of linked list of GrafElements in draw order
  227.     GrafElPtr            idList;            //Head of linked list of GrafElements by ID
  228.  
  229.     //Graphic environment of this world
  230.     GrafPtr                gEWPort;        //Onscreen GrafPort for this world
  231.     GDHandle            portGDevice;    //Device for this port
  232.     GWorldPtr            stageGWorld;    //Offscreen construction "stage" for this world
  233.     Rect                animationRect;    //Total dest rect of this world
  234.     CTabHandle            worldCTable;    //Offscreen color table, should == onscreen cTable
  235.     Point                worldFocus;        //Offset of world from gEWPort top left
  236.     Fixed                worldScale;        //Ratio of screen pixels to world pixels
  237.     
  238.     //Current state of this world
  239.     GraphicLoadFunc        defaultLoader;    //Loader used if no other is specified
  240.     LHeaderPtr            activeRectList;    //Two lists of update rects, so that animation and
  241.     LHeaderPtr            safeRectList;    //screen updating can be concurrent
  242.     LHeaderPtr            sensorList;        //Sensors in this world, see Sensors.h
  243.     GETMgrRec            worldTime;        //Timer record for this world
  244.     unsigned long        lastFrameTime;    //last time screen was updated
  245.     short                msPerFrame;        //minimum "projection" interval, ms
  246.     Boolean                active;            //True if this animation is running
  247.     Boolean                changed;        //True if at least 1 object needs drawing
  248.     
  249. } GEWorld;
  250.  
  251. #endif